<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./lib/vue.js"></script>
</head>
<body>
    <div id="app">
        <son v-bind:parentmsg="msg" @func="getMsgFormSon"></son>
    </div>
    <template id="tmpl">
        <div>
            <h1>这是子组件---{{parentmsg}}</h1>
            <input type="button" value="向父组件传递消息" @click="sendMsg">
        </div>
    </template>
    <script>
        // 声明一个子组件
        var son = {
            template: '#tmpl',
            data(){
                return {
                    msg: 'give father some money'
                }
            },
            props:['parentmsg'],
            methods: {
                sendMsg(){
                    this.$emit('func',this.msg)
                }
            },
        }
        // 父元素
        var vm = new Vue({
            el: "#app",
            data: {
                msg: 'father: I have 100$',
                msgFormSon: ''
            },
            methods: {
                getMsgFormSon(data){
                    this.msgFormSon = data
                    console.log(this.msgFormSon);
                }
            },
            components: {
                son
            }
        });
    </script>
</body>
</html>